package com.sj.排序算法;

import java.util.Arrays;

/**
 * @author sj
 * @date 2021/5/2
 **/
public class 插入排序 {
    public static void main(String[] args) {
        int[] arr = {2, 5, 3, 6, 4, 2, 5, 1, 2};
        charu(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void charu(int[] arr){
        for (int i = 1;i<arr.length;i++){
            int temp = arr[i];
            int index = i -1;
            while (index >= 0 && arr[index]>=temp){
                arr[index+1] = arr[index];
                index--;
            }
            arr[index+1] = temp;
        }
    }
}
